const chai = require("chai");
const chaiHttp = require("chai-http");
chai.should();
chai.use(chaiHttp);

const PREFIX = "http://127.0.0.1:8603";
/**
 * 用户测试
 */
describe("用户测试", () => {

    before(() => {
        console.log("before");
    });

    beforeEach(() => {
        console.log("beforeEach");
    });


    it("测试创建用户", (done) => {

        chai.request(PREFIX)
            .post("/users/create")
            .send({
                nickname: "测试创建用户",
                username: "have1568",
                password: "123456",
                age: 28
            }).end((error, response) => {

            response.should.have.status(200);
            response.body.should.be.a("json");
            response.body.should.have.property("code").eq(200);
            done();
        });
    });

    it("测试获取所有用户", (done) => {
        chai.request(PREFIX)
            .get("/users/list")
            .query({
                page: 0,
                size: 10
            })
            .end((error, response) => {
                console.log(response.body);
                response.should.have.status(200);
                response.body.should.have.property("code").eq(200);
                done();
            });
    });

    it("测试根据用户名搜索", (done) => {
        chai.request(PREFIX)
            .get("/users/search")
            .query({
                nickname: "测试",
                page: 0,
                size: 10
            })
            .end((error, response) => {
                console.log(response.body);
                response.should.have.status(200);
                response.body.should.have.property("code").eq(200);
                done();
            });
    });

    it("测试根据ID获取用户", (done) => {
        chai.request(PREFIX)
            .get("/users/getOne/841e6823-8eaf-43a6-b1b4-a396df7bf7c7")
            .end((error, response) => {
                console.log(response.body);
                response.should.have.status(200);
                response.body.should.have.property("code").eq(200);
                done();
            });
    });


    it("测试更新用户", (done) => {
        chai.request(PREFIX)
            .post("/users/update/841e6823-8eaf-43a6-b1b4-a396df7bf7c7")
            .send({
                nickname: "测试更新用户",
                username: "have1568",
                password: "123456",
                age: 82
            })
            .end((error, response) => {
                console.log(response.body);
                response.should.have.status(200);
                response.body.should.have.property("code").eq(200);
                done();
            });
    });


    afterEach(() => {
        console.log("afterEach");
    });

    after(() => {
        console.log("after");
    });
});
